package fresponse

import (
	"github.com/gin-gonic/gin"
)

type response interface {
	Assemble(ctx *gin.Context)
}

type Option struct {
	HttpCode int
}

func Format(ctx *gin.Context, resp any, err error) {
	if err != nil {
		fail(-1, err.Error()).Assemble(ctx)
	} else {
		if v, ok := resp.(response); ok {
			v.Assemble(ctx)
		} else {
			Json(1, resp).Assemble(ctx)
		}
	}
}
